import Vue from "vue"
import VueRouter from "vue-router"
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css'
import Layout from "@/layout"

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

NProgress.configure({ showSpinner: false }) // NProgress Configuration


export const constantRoutes = [{
  path: '/',
  name: '首页',
  component: Layout,
  children: [{
    path: '',
    name: '首页',
    component: () => import('@/pages/home/index')
  }]
},

{
  path: '/solution',
  component: Layout,
  name: '解决方案',
  children: [{
    path: 'trace',
    name: '区块链溯源解决方案',
    component: () => import('@/pages/solution/trace/index')
  },
  {
    path: 'financial',
    name: '区块链金融解决方案',
    component: () => import('@/pages/solution/financial/index')
  },
  {
    path: 'digital',
    name: '区块链数字政务解决方案',
    component: () => import('@/pages/solution/digital/index')
  },
  {
    path: 'software',
    name: '区块链软件解决方案',
    component: () => import('@/pages/solution/software/index')
  },
  {
    path: 'copyright',
    name: '区块链版权解决方案',
    component: () => import('@/pages/solution/copyright/index')
  },
  {
    path: 'chainChange',
    name: '全栈链改解决方案',
    component: () => import('@/pages/solution/chainChange/index')
  },
  {
    path: 'governance',
    name: '数据治理解决方案',
    component: () => import('@/pages/solution/governance/index')
  }]
},
{
  path: '/product',
  component: Layout,
  name: '产品',
  children: [{
    path: 'one',
    name: '鲸势BOX区块链一体机',
    component: () => import('@/pages/product/one/index')
  },
  {
    path: 'platform',
    name: '鲸势区块链溯源平台',
    isExternal: true,
    linkUrl: "https://dgadm.jstrace.cn"
    // component: () => import('@/pages/product/platform/index')
  }]
},
{
  path: '/about',
  component: Layout,
  name: '关于我们',
  children: [
    {
      path: '',
      name: '关于我们',
      component: () => import('@/pages/about/index')
    }
  ]
}]


const createRouter = () => new VueRouter({
  // 设置路由高亮的全局calss名称
  mode: 'history',
  linkActiveClass: "active",
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

router.beforeEach((to, from, next) => {
  NProgress.start()
  next()
})

router.afterEach(route => {
  NProgress.done()
})


export default router
